/*
========================================================================
 Name        : FRamI_UIMainContainerView.cpp
 Author      : Lenka Litvova
 Copyright   : Copyright belongs to Lenka Litvova
 Description : 
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <barsread.h>
#include <eikimage.h>
#include <eikenv.h>
#include <akncontext.h>
#include <akntitle.h>
#include <stringloader.h>
#include <eikbtgpc.h>
#include <gdi.h>
#include <eikseced.h>
#include <aknquerydialog.h>
#include <aknnotewrappers.h>
#include <FRamI_UI.rsg>
// ]]] end generated region [Generated System Includes]

#include "FRamI_UIAppUi.h"

// [[[ begin generated region: do not modify [Generated User Includes]

#include "FRamI_UI.hrh"
#include "FRamI_UIMainContainerView.h"
#include "FRamI_UIMainContainer.hrh"
#include "FRamI_UISettingList.hrh"
#include "FRamI_UIUsersList.hrh"
#include "FRamI_UIMainContainer.h"
// ]]] end generated region [Generated User Includes]

// [[[ begin generated region: do not modify [Generated Constants]
// ]]] end generated region [Generated Constants]

/**
 * First phase of Symbian two-phase construction. Should not contain any
 * code that could leave.
 */
CFRamI_UIMainContainerView::CFRamI_UIMainContainerView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	iFRamI_UIMainContainer = NULL;
	// ]]] end generated region [Generated Contents]
	
	}

/** 
 * The view's destructor removes the container from the control
 * stack and destroys it.
 */
CFRamI_UIMainContainerView::~CFRamI_UIMainContainerView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	delete iFRamI_UIMainContainer;
	iFRamI_UIMainContainer = NULL;
	// ]]] end generated region [Generated Contents]
	
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance then calls the second-phase constructor
 * without leaving the instance on the cleanup stack.
 * @return new instance of CFRamI_UIMainContainerView
 */
CFRamI_UIMainContainerView* CFRamI_UIMainContainerView::NewL()
	{
	CFRamI_UIMainContainerView* self = CFRamI_UIMainContainerView::NewLC();
	CleanupStack::Pop( self );
	return self;
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance, pushes it on the cleanup stack,
 * then calls the second-phase constructor.
 * @return new instance of CFRamI_UIMainContainerView
 */
CFRamI_UIMainContainerView* CFRamI_UIMainContainerView::NewLC()
	{
	CFRamI_UIMainContainerView* self = new ( ELeave ) CFRamI_UIMainContainerView();
	CleanupStack::PushL( self );
	self->ConstructL();
	return self;
	}


/**
 * Second-phase constructor for view.  
 * Initialize contents from resource.
 */ 
void CFRamI_UIMainContainerView::ConstructL()
	{
	// [[[ begin generated region: do not modify [Generated Code]
	BaseConstructL( R_FRAM_I_UIMAIN_CONTAINER_FRAM_I_UIMAIN_CONTAINER_VIEW );
				
	// ]]] end generated region [Generated Code]
	
	// add your own initialization code here
	
	}

/**
 * @return The UID for this view
 */
TUid CFRamI_UIMainContainerView::Id() const
	{
	return TUid::Uid( EFRamI_UIMainContainerViewId );
	}

/**
 * Handle a command for this view (override)
 * @param aCommand command id to be handled
 */
void CFRamI_UIMainContainerView::HandleCommandL( TInt aCommand )
	{
	// [[[ begin generated region: do not modify [Generated Code]
	TBool commandHandled = EFalse;
	switch ( aCommand )
		{	// code to dispatch to the AknView's menu and CBA commands is generated here
		case EFRamI_UIMainContainerViewNastaveniaMenuItemCommand:
			commandHandled = HandleNastaveniaMenuItemSelectedL( aCommand );
			break;
		case EFRamI_UIMainContainerViewPridaj_autorizovan_osobuMenuItemCommand:
			commandHandled = HandlePridaj_autorizovan_osobuMenuItemSelectedL( aCommand );
			break;
		case EFRamI_UIMainContainerViewKameraMenuItemCommand:
			commandHandled = HandleKameraMenuItemSelectedL( aCommand );
			break;
		case EFRamI_UIMainContainerViewZo_s_boruMenuItemCommand:
			commandHandled = HandleZo_s_boruMenuItemSelectedL( aCommand );
			break;
		case EFRamI_UIMainContainerViewUkon_iMenuItemCommand:
			commandHandled = HandleUkon_iMenuItemSelectedL( aCommand );
			break;
		default:
			break;
		}
	
		
	if ( !commandHandled ) 
		{
	
		}
	// ]]] end generated region [Generated Code]
	if(aCommand == EAknSoftkeyDone)
		((CFRamI_UIAppUi*)AppUi())->SendToBackground();
	}

/**
 *	Handles user actions during activation of the view, 
 *	such as initializing the content.
 */
void CFRamI_UIMainContainerView::DoActivateL( 
		const TVwsViewId& /*aPrevViewId*/,
		TUid /*aCustomMessageId*/,
		const TDesC8& /*aCustomMessage*/ )
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	SetupStatusPaneL();
	
				
				
	
	if ( iFRamI_UIMainContainer == NULL )
		{
		iFRamI_UIMainContainer = CreateContainerL();
		iFRamI_UIMainContainer->SetMopParent( this );
		AppUi()->AddToStackL( *this, iFRamI_UIMainContainer );
		} 
	// ]]] end generated region [Generated Contents]
	
	}

/**
 */
void CFRamI_UIMainContainerView::DoDeactivate()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CleanupStatusPane();
	
	if ( iFRamI_UIMainContainer != NULL )
		{
		AppUi()->RemoveFromViewStack( *this, iFRamI_UIMainContainer );
		delete iFRamI_UIMainContainer;
		iFRamI_UIMainContainer = NULL;
		}
	// ]]] end generated region [Generated Contents]
	
	}

/** 
 * Handle status pane size change for this view (override)
 */
void CFRamI_UIMainContainerView::HandleStatusPaneSizeChange()
	{
	CAknView::HandleStatusPaneSizeChange();
	
	// this may fail, but we're not able to propagate exceptions here
	TVwsViewId view;
	AppUi()->GetActiveViewId( view );
	if ( view.iViewUid == Id() )
		{
		TInt result;
		TRAP( result, SetupStatusPaneL() );
		}
	
	// [[[ begin generated region: do not modify [Generated Code]
	// ]]] end generated region [Generated Code]
	
	}

// [[[ begin generated function: do not modify
void CFRamI_UIMainContainerView::SetupStatusPaneL()
	{
	// reset the context pane
	TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
	CEikStatusPaneBase::TPaneCapabilities subPaneContext = 
		StatusPane()->PaneCapabilities( contextPaneUid );
	if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
		{
		CAknContextPane* context = static_cast< CAknContextPane* > ( 
			StatusPane()->ControlL( contextPaneUid ) );
		context->SetPictureToDefaultL();
		}
	
	// setup the title pane
	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
	CEikStatusPaneBase::TPaneCapabilities subPaneTitle = 
		StatusPane()->PaneCapabilities( titlePaneUid );
	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
		{
		CAknTitlePane* title = static_cast< CAknTitlePane* >( 
			StatusPane()->ControlL( titlePaneUid ) );
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_FRAM_I_UIMAIN_CONTAINER_TITLE_RESOURCE );
		title->SetFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
				
	}

// ]]] end generated function

// [[[ begin generated function: do not modify
void CFRamI_UIMainContainerView::CleanupStatusPane()
	{
	}

// ]]] end generated function

/**
 *	Creates the top-level container for the view.  You may modify this method's
 *	contents and the CFRamI_UIMainContainer::NewL() signature as needed to initialize the
 *	container, but the signature for this method is fixed.
 *	@return new initialized instance of CFRamI_UIMainContainer
 */
CFRamI_UIMainContainer* CFRamI_UIMainContainerView::CreateContainerL()
	{
	return CFRamI_UIMainContainer::NewL( ClientRect(), NULL, this );
	}

// [[[ begin generated function: do not modify
/**
 * Show the popup dialog for pinQuery
 * @param aData in-out TDes data
 * @param aUseDefaults TBool use designer default editor data if ETrue
 * @param aOverridePrompt optional override prompt text
 * @return EAknSoftkeyOk (left soft key id) or 0
 */
TInt CFRamI_UIMainContainerView::RunPinQueryL( 
		TDes& aData, 
		TBool aUseDefaults, 
		const TDesC* aOverridePrompt )
	{
	if ( aUseDefaults )
		{
	
		}
				
	CAknTextQueryDialog* queryDialog = CAknTextQueryDialog::NewL( aData );	
	
	if ( aOverridePrompt != NULL )
		{
		//CleanupStack::PushL( queryDialog );
		queryDialog->SetPromptL( *aOverridePrompt );
		//CleanupStack::Pop(); // queryDialog
		}
	
	return queryDialog->ExecuteLD( R_FRAM_I_UIMAIN_CONTAINER_PIN_QUERY );
	}
// ]]] end generated function

/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CFRamI_UIMainContainerView::HandleNastaveniaMenuItemSelectedL( TInt aCommand )
	{
		((CFRamI_UIAppUi*)AppUi())->ShowSettings();
		return ETrue;
	}
				
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CFRamI_UIMainContainerView::HandlePridaj_autorizovan_osobuMenuItemSelectedL( TInt aCommand )
	{
		((CFRamI_UIAppUi*)AppUi())->ShowUsersAdministration();
		return ETrue;
	}
		
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CFRamI_UIMainContainerView::HandleKameraMenuItemSelectedL( TInt aCommand )
	{
		((CFRamI_UIAppUi*)AppUi())->CaptureAuthImage();
		return ETrue;
	}

/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CFRamI_UIMainContainerView::HandleZo_s_boruMenuItemSelectedL( TInt aCommand )
	{
		((CFRamI_UIAppUi*)AppUi())->SearchForAuthImageFile();
		return ETrue;
	}
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CFRamI_UIMainContainerView::HandleUkon_iMenuItemSelectedL( TInt aCommand )
	{
	AppUi()->HandleCommandL( EEikCmdExit );
	return ETrue;
	}
				
// [[[ begin generated function: do not modify
/**
 * Show the popup note for AuthetificationResult
 * @param aOverrideText optional override text
 */
void CFRamI_UIMainContainerView::RunAuthetificationResultL( const TDesC* aOverrideText )
	{
	CAknInformationNote* note = new ( ELeave ) CAknInformationNote();
	if ( aOverrideText == NULL )
		{
		HBufC* noteText = StringLoader::LoadLC( R_FRAM_I_UIMAIN_CONTAINER_AUTHETIFICATION_RESULT );
		note->ExecuteLD( *noteText );
		CleanupStack::PopAndDestroy( noteText );
		}
	else
		{
		note->ExecuteLD( *aOverrideText );
		}
	}
// ]]] end generated function

